﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cemit.NetFramework
{
    class Pool<T>
    {
        private readonly Queue<int> poolIds = new Queue<int>();
        private readonly List<T> pool = new List<T>() { default };

        public int Push(T report)
        {
            if (poolIds.Count == 0)
            {
                pool.Add(report);
                return pool.Count - 1;
            }

            var id = poolIds.Dequeue();
            pool[id] = report;
            return id;
        }

        public T Pop(int id)
        {
            poolIds.Enqueue(id);
            return pool[id];
        }
    }
}
